{% extends "base.html" %} {% block main %}
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h1>Sign in successfully!</h1>
            <div class="alert alert-success"> <strong>Well done!</strong> You successfully signed in as <strong>{{ name }}</strong>!
                <br>Your BlockChain account is: <strong><span id ='account'>{{account}}</span></strong>
                <br>Your Eth balance is:<strong><span id ='eth'>{{eth}}</span></strong>
                <br>Your DenCarToken balance is:<strong><span id = 'denCar'>{{denCar}}</span></strong>
            </div>
        </div>
    </div>
</div>
<span id = 'thisAccount' style="display: none">{{email}}</span>
<div class="container">

            <div class="row">

            <div class="col-md-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><span class="glyphicon glyphicon-user"></span>Buy DenCar Token  </h3>
                    </div>
                    <div class="panel-body">
                        <form>
                            <div class="form-group">
                                <label>Amount(Eth)</label>
                                <input id="buyAmount" name="buyAmount" class="form-control" placeholder="5000 per 1ETH">
                            </div>
                            <button class="btn btn-primary" onclick="buyToken()">Buy</button>
                        </form>
                    </div>
                </div>
            </div>

            <div class="col-md-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><span class="glyphicon glyphicon-user"></span>Send Token  </h3>
                    </div>
                    <div class="panel-body">
                        <form>
                        <div class="form-group">
                            <label>toAddress</label>
                            <input id="toAddress"  class="form-control" >
                        </div>
                        <div class="form-group">
                            <label>Amount</label>
                            <input id="sendAmount" name="sendAmount" class="form-control" >
                        </div>
                        </form>
                        <button class="btn btn-primary" onclick="sendToken()">Send</button>
                    </div>
                </div>
            </div>
                <div class="col-md-6" style="margin-top: 50px;">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title"><span class="glyphicon glyphicon-user"></span>Give Comment  </h3>
                        </div>
                        <div class="panel-body">
                            <div class="form-group">
                                <label>to account</label>
                                <input id="toAccount" name="toAccount" class="form-control" placeholder="eg huangkenc@126.com">
                            </div>
                            <div class="form-group">
                                <label>content</label>
                                <input id="content" name="content" class="form-control" placeholder="eg 非常好">
                            </div>
                            <div class="form-group">
                                <label>content</label>
                                <input id="star" name="star" class="form-control" placeholder="eg 5">
                            </div>
                            <button class="btn btn-primary" onclick="giveComment()">commit</button>
                        </div>
                    </div>
                </div>

            </div>

    <p><a href="/">Back to home</a></p>
</div>
<script>
    //ajax请求， 购买代币
    function buyToken() {
        var address = document.getElementById("account").innerHTML;
        var amount = document.getElementById("buyAmount").value;
        //alert(name);
        $.post('/api/buyToken',{userAddress:address,amount:amount},function(data)

        {
            alert('购买成功！');
            document.getElementById("denCar").innerHTML = data['data'];

        })
    }
    //发送代币给司机等
    function sendToken() {
        var fromAddress = document.getElementById("account").innerHTML;
        var toAddress = document.getElementById("toAddress").value;

        var amount = document.getElementById("sendAmount").value;
        //alert(name);
        $.post('/api/sendToken',{fromAddress:fromAddress,toAddress:toAddress,amount:amount},function(data)

        {
            alert('发送成功！');
            document.getElementById("denCar").innerHTML = data['data'];

        })
    }
    //提交评价，存储于数据库
    function giveComment() {
        var fromAccount = document.getElementById("thisAccount").innerText;

        var toAccount = document.getElementById("toAccount").value;
        var content = document.getElementById("content").value;

        var star = document.getElementById("star").value;
        $.post('/api/giveComment',{fromAccount:fromAccount,toAccount:toAccount,content:content,star:star},function(data)

        {
            alert('发送成功！');

        })
    }
</script>
{% endblock %}